var express = require('express');
var getRouter = express.Router();
var postRouter = express.Router();
var axios = require('axios')
var rootApi = "http://112.74.105.17:20003/question-bank"
/* GET users listing. */
getRouter.get('/findExamList', function (req, res, next) {
    console.log(req.query.data)
    var thisApi = '/wx/answer/stem'
    // axios.get(rootApi + thisApi + questionId)
    //     .then(function (response) {
    //         res.send(response.data);
    //     })
    //     .catch(function (error) {
    //         console.log(error);
    //     });

});

postRouter.post('/findExamList', function (req, res, next) {
    //租户id 757021031830388736 是我们组的，必选参数，其他可以不要，所以租户id在这里写死了
    var thisApi = '/wx/exam/findExamList'

    var gradeName = ''
    var groupName = ''
    var subject = ''
    var tenantId = "757021031830388736"
    console.log(JSON.stringify(req.body))
    if (req.body.gradeName != null) {
        gradeName = JSON.stringify(req.body.gradeName)
        gradeName = gradeName.substring(1, (gradeName.length - 1))
    }
    // console.log(gradeName)
    if (req.body.groupName != null) {
        groupName = JSON.stringify(req.body.groupName)
        groupName = groupName.substring(1, (groupName.length - 1))
    }
    // console.log(groupName)
    if (req.body.subject != null) {
        subject = JSON.stringify(req.body.subject)
        subject = subject.substring(1, (subject.length - 1))
    }
    // console.log(subject)
    //写到这里，返回试卷列表
    axios.post(rootApi + thisApi, {
        gradeName: gradeName,
        groupName: groupName,
        subject: subject,
        tenantId: tenantId
    })
        .then(function (response) {
            res.send(response.data)
        })
        .catch(function (error) {
            console.log(error);
        });
});

exports.get = getRouter;
exports.post = postRouter;
// module.exports = router;
